package ysq.xyg.host.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.host.model.po.HostArea;
import ysq.xyg.host.model.vo.HostAreaVo;
import ysq.xyg.host.service.HostAreaService;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.sys.service.SysUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
 * 房产模块-区域controller层
 *
 * @author shengQiang yu
 * @date 2019-7-1 13:58:43
 */
@RestController
public class HostAreaController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(HostAreaController.class);
    @Resource
    private HostAreaService hostAreaService;
    @Resource
    private SysUserService sysUserService;
    private HostArea hostArea;

    /**
     * 分页查询
     *
     * @param hostAreaVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-7-1 13:58:43
     */
    @BaseLog(module = "房产模块",className = "区域",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostArea/page",method = RequestMethod.POST)
    public ReturnEntity page(HostAreaVo hostAreaVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = hostAreaService.page(hostAreaVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-1 13:58:43
     */
    @RequestMapping(value = "/hostArea/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/host/hostAreaUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            hostArea = hostAreaService.selectByPrimaryKey(id);
            if(hostArea!=null&&StrUtil.isNotEmpty(hostArea.getUserId())){
                SysUser sysUser=sysUserService.selectByPrimaryKey(hostArea.getUserId());
                if(sysUser!=null){
                    hostArea.setUserName(sysUser.getUserName());
                    hostArea.setUserPhone(sysUser.getUserPhone());
                }
            }
            view.addObject("hostArea", hostArea);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-1 13:58:43
     */
    @BaseLog(module = "房产模块",className = "区域",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostArea/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return hostAreaService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param hostAreaVo Vo对象
     * @author shengQiang yu
     * @date 2019-7-1 13:58:43
     */
    @BaseLog(module = "房产模块",className = "区域",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostArea/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,HostAreaVo hostAreaVo){
        return hostAreaService.addOrUpdate(hostAreaVo,acceptCurrentUser(request));
    }
    /**
     * 获取城市区域树
     *
     * @param hostAreaVo Vo对象
     * @author shengQiang yu
     * @date 2019-4-2 15:43:10
     */
    @BaseLog(module = "房产模块",className = "区域",methods = "城市区域树",businessType =BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostArea/dTreeList",method = RequestMethod.POST)
    public ReturnEntity dTreeList(HostAreaVo hostAreaVo){
        return hostAreaService.dTreeList(hostAreaVo);
    }
}